package cn.com.zpark;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @PackageName: cn.com.zpark
 * @ClassName: JDBC_03_Update
 * @Description: JDBC修改数据
 * @author: RZS
 * @date: 2021/10/25  15:42
 */
public class JDBC_03_Update {
    public static void main(String[] args) {
        String url = "jdbc:mysql://192.168.80.142:3306/mydb1?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8";
        Connection conn = null;
        Statement stat = null;
        try {
            // 1、注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            // 2、获取连接
            conn = DriverManager.getConnection(url, "root", "root");
            // 3、创建statement对象
            stat = conn.createStatement();
            // 4、编写sql语句
            String sql = "update user set money=1000.0";
            // 5、执行sql
            stat.executeUpdate(sql);
            // 6、获取执行结果
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 7、关闭连接
            if (stat != null) {
                try {
                    stat.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
